<?php
/**
 * Eren Framework
 * 
 * Filter Operate Class
 * 
 * @category System
 * @author Manu Soros Leu
 * @copyright manusoros@gmail.com
 */

class Eren_Filter
{
    /**
     * Add backslashes before special characters prevent from operating DB error
     * 
     * @param string $data
     * @return string
     */
    public static function addslashes($data)
    {
        if(!get_magic_quotes_gpc()){
            if(!is_array($data)){
                $data = addslashes($data);
            }else{
                foreach ($data as $key=>$value){
                    $data[$key] = self::addslashes($value);
                }
            }
        }
        return $data;
    }
    
    /**
     * Remove backslashes for special characters which added by addslashes
     * 
     * @param string $data
     * @return string
     */
    public static function stripslashes($data)
    {
        if(!get_magic_quotes_gpc()){
            if(!is_array($data)){
                $data = stripslashes($data);
            }else{
                foreach ($data as $key=>$value){
                    $data[$key] = self::stripslashes($value);
                }
            }
        }
        return $data;
    }
    
    /**
     * Translate HTML character prevent from being represented by HTML entities
     * 
     * @param string $data
     * @return string
     */
    public static function htmlspecialchars($data)
    {
        if(!is_array($data)){
            $data = htmlspecialchars($data, ENT_QUOTES);
        }else{
            foreach ($data as $key=>$value){
                $data[$key] = self::htmlspecialchars($value);
            }    
        }
        return $data;
    }
    
    /**
     * Decode HTML character
     * 
     * @param string $data
     * @return string
     */
    public static function htmlspecialchars_decode($data)
    {
        if(!is_array($data)){
            $data = htmlspecialchars_decode($data, ENT_QUOTES);
        }else{
            foreach ($data as $key=>$value){
                $data[$key] = self::htmlspecialchars_decode($value);
            }    
        }
        return $data;
    }
}